home *** CD-ROM | disk | FTP | other *** search
- #pragma once
- /*****
- *
- * Grant's CGI Framework
- *
- * CGI.h
- *
- * standard types and function prototypes for cgi applications
- * See the Read Me or CGI.c for instructions on using the CGI Utilities
- *
- * #include this file in your source files that need to access the cgi module
- *
- * This is a support file for "Grant's CGI Framework".
- * Please see the license agreement that accompanies the distribution package
- * for licensing details.
- *
- * Copyright ©1995,1996 by Grant Neufeld
- *
- * http://arpp.carleton.ca/cgi/framework/
- * gneufeld@ccs.carleton.ca
- * grant@acm.org
- *
- *****/
-
- #include "MyConfiguration.h"
- #if kCompileWithCGICode
-
- #include <Threads.h>
- #if kCompilingForWSAPI
- #include <WSAPI.h>
- #else
- #include "MemoryUtil.h"
- #endif
-
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
-
- /*** CONSTANT DECLARATIONS ***/
-
- #define kCGIHTTPMethodGet "GET"
- #define kCGIHTTPMethodPost "POST"
- #define kCGIHTTPMethodGetConditional "GET_CONDITIONAL"
- #define kCGIHTTPMethodConditionalGet "CONDITIONAL_GET"
-
- #define kCGIFormFieldDelimiter '='
- #define kCGIFormFieldSeparator '&'
-
- /* Apple events */
-
- enum {
- kAEClassCGI = 'WWWΩ',
- kAEIDSearchDoc = 'sdoc',
-
- /* CGI event parameters */
- kCGIpath_args = '----',
- kCGIhttp_search_args = 'kfor',
- kCGIusername = 'user',
- kCGIpassword = 'pass',
- kCGIfrom_user = 'frmu',
- kCGIclient_address = 'addr',
- kCGIpost_args = 'post',
- kCGImethod = 'meth',
- kCGIserver_name = 'svnm',
- kCGIserver_port = 'svpt',
- kCGIscript_name = 'scnm',
- kCGIcontent_type = 'ctyp',
- kCGIcontent_length = 'CLen',
- kCGIreferer = 'refr',
- kCGIuser_agent = 'Agnt',
- kCGIaction = 'Kact',
- kCGIaction_path = 'Kapt',
- kCGIclient_ip = 'Kcip',
- kCGIfull_request = 'Kfrq',
- kCGIversion = 'Pvrs',
- kCGIconnection = 'Kcid'
- };
-
- /* for an official listing of the maximum sizes for CGI parameters,
- <http://www.biap.com/datapig/mrwheat/cgi_params.html> */
- enum {
- kCGIParamMaxSize = 32769,
-
- kCGIMaxpath_args = 1024,
- kCGIMaxhttp_search_args = 1024,
- kCGIMaxusername = 32,
- kCGIMaxpassword = 32,
- kCGIMaxfrom_user = 128,
- kCGIMaxclient_address = 256,
- kCGIMaxpost_args = 32768,
- kCGIMaxmethod = 32,
- kCGIMaxserver_name = 256,
- kCGIMaxserver_port = 16,
- kCGIMaxscript_name = 1024,
- kCGIMaxcontent_type = 64,
- kCGIMaxreferer = 1024,
- kCGIMaxuser_agent = 256,
- kCGIMaxaction = 32,
- kCGIMaxaction_path = 1024,
- kCGIMaxclient_ip = 32,
- kCGIMaxfull_request = 4096,
- kCGIMaxconnection = 4
- };
-
- /* Action Names */
- #define kCGIActionNameCGI "CGI"
- #define kCGIActionNameACGI "ACGI"
- #define kCGIActionNamePreProcessor "PREPROCESSOR"
- #define kCGIActionNamePostProcessor "POSTPROCESSOR"
- #define kCGIActionNameLogging "LOGGING"
- #define kCGIActionNameSecurity "SECURITY"
- #define kCGIActionNameError "ERROR"
- #define kCGIActionNameNoAccess "NOACCESS"
- #define kCGIActionNameIndex "INDEX"
-
- /* Send Partial event */
-
- enum {
- kMyAESendPartial = 'SPar',
-
- kCGIPartialData = '----',
- kConnectionIDKeyword = 'Kcid',
- kMoreKeyword = 'Kmor'
- };
-
- #define kCGIPartialStartString "<SEND_PARTIAL>"
-
-
- /*** TYPE DECLARATIONS ***/
-
- #if kCompileWithCGIFormHandling
- typedef struct
- {
- char * name;
- char * value;
- } CGIFormField;
- #endif
-
- #if kCompileWithCGImethod
- typedef enum
- {
- HTTP_UNDEFINED = 0,
- HTTP_get,
- HTTP_post,
- HTTP_getConditional
- } HTTPMethod;
- #endif
-
- #if kCompilingForWSAPI || kCompileWithCGIActionSupport
- typedef enum {
- #ifndef WSAPI_Run_Role
- CGIRole_CGI = 0, /* CGI or ACGI (difference only affects server, not CGI) */
- CGIRole_PreProcessor = 1,
- CGIRole_PostProcessor = 2,
- CGIRole_Logging = 3, /* receiving log info */
- CGIRole_Security = 4, /* access restriction control */
- CGIRole_Error = 5, /* invalid url handling */
- CGIRole_NoAccess = 6, /* client IP or domain denied access */
- CGIRole_Index = 7 /* default file ('/') */
- #else
- CGIRole_CGI = WSAPI_CGI_Role,
- CGIRole_PreProcessor = WSAPI_PreProcessor_Role,
- CGIRole_PostProcessor = WSAPI_PostProcessor_Role,
- CGIRole_Logging = WSAPI_Logging_Role,
- CGIRole_Security = WSAPI_Security_Role,
- CGIRole_Error = WSAPI_Error_Role,
- CGIRole_NoAccess = WSAPI_NoAccess_Role,
- CGIRole_Index = WSAPI_Index_Role
- #endif
- } CGIRole;
- #endif
-
-
- typedef struct
- {
- #if kCompilingForWSAPI
- /* The WSAPI data structure associated with the CGI event.
- This must be the first item in the structure! */
- WSAPI_CommandPBPtr wsapi;
- #endif
-
- /** PUBLIC, READ-ONLY (don't modify these fields in your code) **/
-
- #if kCompileWithCGIpath_args
- char * path_args; /* '----' path_args */
- #endif
- #if kCompileWithCGIhttp_search_args
- char * http_search_args; /* 'kfor' http_search_args */
- #endif
- #if kCompileWithCGIusername
- char username[kCGIMaxusername]; /* 'user' username */
- #endif
- #if kCompileWithCGIpassword
- char password[kCGIMaxpassword]; /* 'pass' password */
- #endif
- #if kCompileWithCGIfrom_user
- char from_user[kCGIMaxfrom_user];/* 'frmu' from_user */
- #endif
- #if kCompileWithCGIclient_address
- char client_address[kCGIMaxclient_address];/* 'addr' client_address */
- #endif
- #if kCompileWithCGIpost_args
- char * post_args; /* 'post' post_args */
- #endif
- #if kCompileWithCGImethod
- HTTPMethod method; /* 'meth' method */
- #endif
- #if kCompileWithCGIserver_name
- char server_name[kCGIMaxserver_name];/* 'svnm' server_name */
- #endif
- #if kCompileWithCGIserver_port
- short server_port; /* 'svpt' server_port */
- #endif
- #if kCompileWithCGIscript_name
- char * script_name; /* 'scnm' script_name */
- #endif
- #if kCompileWithCGIcontent_type
- char content_type[kCGIMaxcontent_type];/* 'ctyp' content_type */
- #endif
- #if kCompileWithCGIcontent_length
- unsigned long content_length;/* 'CLen' content_type */
- #endif
- #if kCompileWithCGIreferer
- char * referer; /* 'refr' referer */
- #endif
- #if kCompileWithCGIuser_agent
- char user_agent[kCGIMaxuser_agent];/* 'Agnt' user_agent */
- #endif
-
- #if kCompileWithCGIActionSupport
- char action[kCGIMaxaction]; /* 'Kact' action */
- char * action_path; /* 'Kapt' action_path */
- #endif
-
- #if kCompileWithCGIActionSupport || kCompilingForWSAPI
- CGIRole role; /* the function that the CGI is being called to perform */
- #endif
-
- #if kCompileWithCGIclient_ip
- #if kCompilingForWSAPI
- long client_ip; /* 'Kcip' client_ip */
- #else
- char client_ip[kCGIMaxclient_ip]; /* 'Kcip' client_ip */
- #endif
- #endif
- #if kCompileWithCGIfull_request
- char * full_request; /* 'Kfrq' full_request */
- #endif
-
- #if kCompileWithCGISendPartial
- long connection; /* 'Kcid' connection */
- #endif
-
- #if kCompilingForWSAPI
- /* these fields are only available to WSAPI plug-ins */
-
- #if kCompileWithCGIfileMIMEType
- /* The MIME type of the URL in piScriptName */
- char * fileMIMEType; /* 'Mime' */
- #endif
- #if kCompileWithCGIserverField
- /* The HTTP header field for this server. e.g., "Server: WebSTAR/1.3 ID/22" */
- char * serverField; /* 'SvFd' */
- #endif
- #if kCompileWithCGIserverDirectoryPath
- /* A C string representing the complete (machine-specific) path name of
- the server's working directory */
- char * serverDirectoryPath; /* 'SPth' */
- #endif
- #if kCompileWithCGIurlPhysicalPath
- /* If the URL represents an actual file in the file system, this parameter
- contains its name relative to the server's root. */
- char * urlPhysicalPath; /* 'UPth' */
- #endif
- #if kCompileWithCGIifModifiedSince
- /* short (really a Boolean). True if the file has been modified since
- last retrieval or if modification cannot be determined.
- False if unchanged. */
- short ifModifiedSince; /* 'IfMS' */
- #endif
- #if kCompileWithCGIcurrentRealm
- /* typeChar, 256 max. The realm (if any) that the requested URL belongs to.
- WSAPI_E_RequestFailed will be returned by GetParameter
- if this value isn't defined for the current request. */
- char currentRealm[256]; /* 'CRlm' */
- #endif
-
- #endif /* kCompilingForWSAPI */
-
- #if kCompileWithCGIFormHandling
- CGIFormField * formFields; /* the fields from form submission */
- long totalFields; /* total number of fields */
- #endif
-
-
- /** PRIVATE. these fields should not be touched outside the CGI.c file **/
-
- #if kCompilingForWSAPI
-
- /* this will be set to true if you return data on the connection from
- within your custom code. */
- Boolean dataSent; /* has data been sent yet? */
-
- #if kCompileWithTCPCode
- WSAPI_Stream tcpStream;
- #endif
-
- #else /* not wsapi */
-
- AppleEvent appleEvent; /* originating appleEvent */
- AppleEvent replyEvent; /* apple event reply record */
-
- #if kCompileWithThreadedAppleEvents
- Boolean suspended; /* whether the AE has been suspended */
- #endif
-
- #if kCompileWithCGISendPartial
- char sendPartialActive; /* boolean - has send partial been used on this CGIRecord already */
- char sendPartialDone; /* boolean - send partial connection has been closed (!sendMore sent) */
- #endif
-
- #if kCompileWithTCPCode
- //••• need to put in tcp support for applications, and not just plug-ins
- #endif
-
- #endif /* !(kCompilingForWSAPI) */
-
-
- /** PUBLIC, READ-WRITE. fields to be filled in **/
-
- #if kCompileWithCGIResponseDataAsHandle
- Handle responseData; /* data to return to the client */
- #else
- char * responseData; /* data to return to the client */
- #endif
- long responseSize; /* size in bytes of the response */
-
- #if kCompileWithCGIRefCon
- long refCon; /* field for storing custom data */
- #endif
- } CGIrecord;
-
- typedef CGIrecord ** CGIHdl;
-
-
- /*** GLOBAL DECLARATIONS ***/
-
- #ifdef __CGISegment__
- #define _GLOBAL_
- #else
- #define _GLOBAL_ extern
- #endif
-
- /* these are globals for holding the standard http headers.
- One of the headers must be prepended to the data returned in the Apple Event */
-
- _GLOBAL_ Str255 gHTTPHeaderOK; /* use data returned after header */
- _GLOBAL_ Str255 gHTTPHeaderRedirect; /* redirect client to different url */
- _GLOBAL_ Str255 gHTTPHeaderErr; /* an application level error */
- #if kCompileWithCGISendPartial
- _GLOBAL_ Str255 gHTTPHeaderPush; /* multipart server push */
- #endif
-
- _GLOBAL_ long gHTTPHeaderOKSize;
- _GLOBAL_ long gHTTPHeaderRedirectSize;
- _GLOBAL_ long gHTTPHeaderErrSize;
- #if kCompileWithCGISendPartial
- _GLOBAL_ long gHTTPHeaderPushSize;
- #endif
-
- #undef _GLOBAL_
-
-
- /*** FUNCTION PROTOTYPES ***/
-
- SInt32 InitCGIUtil ( void );
-
- #if kCompileWithCGIFormHandling
- p_export CGIFormField * CGIFormFieldsFromArgs ( CGIHdl, char *, long *, short * );
- p_export CGIFormField * CGIFormFieldsFindRecord ( CGIHdl, const char * );
- p_export const char * CGIFormFieldsFindValue ( CGIHdl, const char * );
- #endif /* kCompileWithCGIFormHandling */
-
- #if kCompileWithCGIActionSupport
- p_export Boolean CGIActionIsCGIorACGI ( CGIHdl );
- #endif
-
- p_export Boolean CGIIsSecurePath ( char * );
-
- #if kCompileWithCGIfull_request
- p_export Boolean CGIHostNameDifferent ( CGIHdl, char *, short );
- #endif
-
- p_export void CGIDecodeURLChars ( char * );
- p_export char * CGIEncodeURLChars ( CGIHdl, const char *, OSErr * );
- p_export Boolean CGICharWillHex ( unsigned char );
- p_export void CGICharToHex ( unsigned char, char * );
-
- p_export void CGIPathToMacPath ( char * );
-
- #if kCompilingForWSAPI
- p_export char * CGIWSAPIGetParam ( WSAPI_CommandPBPtr, WSAPI_ParamKeywords, void *, UInt32 );
- p_export void CGIWSAPIUseMyResFile ( void );
- p_export void CGIWSAPIResetResFile ( void );
- #else
- #define CGIWSAPIUseMyResFile()
- #define CGIWSAPIResetResFile()
- #endif
-
- p_export OSErr CGISendData ( CGIHdl, void *, long, Boolean );
-
- /* ••• This function is incomplete - don't use it!!! */
- p_export OSErr CGIPassAppleEvent ( CGIHdl, OSType );
-
- p_export void CGILogData ( CGIHdl );
-
- /* Memory Handling */
- #if kCompilingForWSAPI
- /* special memory handling under WSAPI */
- p_export Handle CGINewHandle ( CGIHdl, long, OSErr * );
- p_export Handle CGINewHandleClear ( CGIHdl, long, OSErr * );
- p_export Ptr CGINewPtr ( CGIHdl, long, OSErr * );
- p_export Ptr CGINewPtrClear ( CGIHdl, long, OSErr * );
-
- p_export void CGIDisposeHandle ( CGIHdl, Handle );
- p_export void CGIDisposePtr ( CGIHdl, Ptr );
- #else
- /* wrappers for standard memory handling when not compiling under wsapi */
- #define CGINewHandle(theCGIHdl,theSize,theErr) MemoryNewHandle(theSize,theErr)
- #define CGINewHandleClear(theCGIHdl,theSize,theErr) MemoryNewHandleClear(theSize,theErr)
- #define CGINewPtr(theCGIHdl,theSize,theErr) MemoryNewPtr(theSize,theErr)
- #define CGINewPtrClear(theCGIHdl,theSize,theErr) MemoryNewPtrClear(theSize,theErr)
-
- #define CGIDisposeHandle(theCGIHdl,theHandle) MemoryDisposeHandle(theHandle)
- #define CGIDisposePtr(theCGIHdl,thePtr) MemoryDisposePtr(thePtr)
- #endif
-
-
- #ifdef __cplusplus
- }
- #endif
-
-
- #else /* if not kCompileWithCGICode */
-
- /* these are defined like this here so the StartupApplication function
- doesn't have to be messed with when compiling without the CGI module */
- #define InitCGIUtil() (noErr)
-
- #endif /* kCompileWithCGICode */
-
- /*** EOF ***/
-